package com.citywy.boot.config;

import com.citywy.boot.bean.Pet;
import com.citywy.boot.bean.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.*;


/**
 *
 */
@Configuration(proxyBeanMethods = false) //告诉springboot这是一个配置类==配置文件
@ConditionalOnMissingBean(name = "user")
@ImportResource("classpath:bean.xml")
public class MyConfig {
    @Bean //给容器中添加组件。以方法名作为组件的ID,返回类型就是组件类型,返回的值就是组件在容器中的实例
    public User user(){
        User user = new User("taray", 18);
//        user.setPet(tomcat());
        return user;
    }

    @Bean("tom")
    public Pet tomcat(){
        return new Pet("小咪");
    }
}
